The environment is split up into regions called office regions. Each of these office regions has the responsibility to keeping track of its own environment. \coderef{office-region} shows the code snippet from OfficeRegion, where the OfficeRegion finds out that an User has entered its region. It alerts the other agents in its region (in this example it is only the FloorHeater agent) to change the temperature etc. regarding to the users preferences.

\lstinputlisting[caption={(Code snippets of) OfficeRegion.java},label={office-region}]{Codes/OfficeRegion.java}

Some of the agents should give something to the environment. \coderef{emit-behavior} shows how an actuator can emit through an emitting behaviour, which are oblivious to, what it emits by the use of abstract classes.

\lstinputlisting[caption={(Code snippets of) EmitBehavior.java},label={emit-behavior}]{Codes/EmitBehavior.java}

In \coderef{emit-behavior} the constructMessage is being used. This method can be seen in \coderef{construct-message}, where it is possible to see how the method is constructed without knowing, which agent it is. It uses the other message classes for specializing, what the message should contain.

\lstinputlisting[caption={(Code snippets of) AMessage.java},label={construct-message}]{Codes/constructMessage.java}

\coderef{emit-message} contains one of these specialized construction message methods. The code snippet shows how the EmitMessage make use of one of the abstract classes in the agent tree. It takes the agents value and construct the message.

\lstinputlisting[caption={(Code snippets of) EmitMessage.java},label={emit-message}]{Codes/EmitMessage.java}

The message should be returned from this string (See \coderef{retrieve-message}). The procedure is the same somewhat just reversed. \coderef{retrieve-message} shows the first part of retrieving the message. This part determines, what kind of a message it is. It creates the message object and returns it to the agent as a AMessage. The agent can then ask what kind of message it is and then cast AMessage to the right message and retrieved the information.

\lstinputlisting[caption={(Code snippets of) AMessage.java},label={retrieve-message}]{Codes/retrieveMessage.java}
